package org.example.service.impl;

import org.example.mapper.DeptMapper;
import org.example.pojo.Dept;
import org.example.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Random;

@Service
public class DeptServiceImpl implements DeptService {

    @Autowired
    private DeptMapper deptMapper;


    /**
     * 查询所有部门信息
     * @return
     */
    @Override
    public List<Dept> findAll() {
        List<Dept> deptList = deptMapper.selectAll();
        return deptList;
    }

    /**
     * 根据id删除部门
     * @param id
     */
    @Transactional
    @Override
    public void deleteById(Integer id) {
        deptMapper.deleteById(id);
    }

    /**
     * 添加部门
     * @param dept
     */
    @Transactional
    @Override
    public void insert(Dept dept) {
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.insert(dept);
    }

    /**
     * 修改部门信息
     * @param dept
     */
    @Transactional
    @Override
    public void update(Dept dept) {
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.update(dept);
    }

    /**
     * 根据id查询部门信息
     * @param id
     * @return
     */
    @Override
    public Dept findById(Integer id) {
        Dept dept=deptMapper.selectById(id);
        return dept;
    }
}
